const express = require('express')
let bodyparser = require('body-parser')
const router = require('./route/login')
let app = express()
const session = require('express-session')
const mongostore = require('connect-mongo')
// 设置express-session中间件
app.use(session({
  secret: 'keyboard cat',
  resave: false,
  saveUninitialized: false,
  store: mongostore.create({
    mongoUrl: 'mongodb://127.0.0.1:27017/mymongodb'
  }),
  cookie: {
    secure: true,
    maxAge: 1000 * 60 * 5
  }
}))
// 解析请求报文中的json和urlencode
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(bodyparser.urlencoded({ extended: false }))
app.use(bodyparser.json())

app.use(router)
app.listen(9000, function () {
  console.log('9000端口的监听已开启');
})